package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo add(@RequestBody Cart cartParam) {
        Cart cart = cartService.add(cartParam);
        return ResultInfo.success(cart);
    }

    //查询我的购物车
    @GetMapping("/cart/list")
    public ResultInfo findList() {
        List<Cart> cartList = cartService.findList();
        return ResultInfo.success(cartList);
    }

    //修改购物车
    @PostMapping("/cart/sub")
    public ResultInfo update(@RequestBody Cart cartParam) {

        Cart cart = cartService.update(cartParam);
        return ResultInfo.success(cart);
    }

    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo clean() {
        cartService.clean();
        return ResultInfo.success(null);
    }
}
